from dataclasses import dataclass
from typing import Dict, List, Any, Optional

@dataclass
class BrainWaveRatesInput:
    session_id: str
    start_time: str
    end_time: str
    relative_rates: Dict[str, List[float]]

@dataclass
class BrainStateOutput:
    """
    脑状态输出结果
    
    Attributes:
        session_id: 会话ID
        state: 脑状态（如：放松、专注、冥想、正常）
        confidence: 置信度 (0.0-1.0)
        details: 详细信息，包含各频段占比等
    """
    session_id: str
    state: str
    confidence: float
    details: Dict[str, Any]

@dataclass
class DeviceConnectionRequest:
    """
    设备连接请求参数
    
    Attributes:
        port: 设备端口（可选，如 COM3、/dev/ttyUSB0 等）
        room_id: 房间ID（可选，用于标识数据所属房间）
    """
    port: Optional[str] = None
    room_id: Optional[str] = None

@dataclass
class AnalysisParams:
    """
    脑波分析参数
    
    Attributes:
        window_size: 分析窗口大小（秒）
        overlap: 窗口重叠比例 (0.0-1.0)
        bands: 频段配置
        analysis_interval: 脑状态分析时间间隔（秒），控制BrainStateService的分析频率
        data_buffer_size: 数据缓冲区大小，用于累积指定时间间隔的数据
    """
    window_size: int = 5
    overlap: float = 0.5
    bands: Dict[str, List[float]] = None
    analysis_interval: int = 5  # 默认5秒分析一次
    data_buffer_size: int = 10  # 默认缓冲10个数据点
    
    def __post_init__(self):
        if self.bands is None:
            self.bands = {
                "delta": [0.5, 4.0],
                "theta": [4.0, 8.0],
                "alpha": [8.0, 13.0],
                "beta": [13.0, 30.0],
                "gamma": [30.0, 100.0]
            }